/**
 * 写入数据，后续备用
 */

const mongoose = require("mongoose");
const films = require("./00.json");

async function main() {
  try {
    await mongoose.connect("mongodb://127.0.0.1/maizuo");

    const filmSchema = new mongoose.Schema({
      filmId: Number,
      name: String,
      poster: String,
      actors: [
        {
          name: String,
          role: String,
        },
      ],
      director: String,
      category: String,
      synopsis: String,
      premiereAt: Number,
      runtime: Number,
    });

    const FilmModel = mongoose.model("Film", filmSchema);

    // 写
    await FilmModel.insertMany(films);

    console.log("操作成功");
  } catch (error) {
    console.error("出错了", error);
  }
}

main();
